/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.joseph.validation.concrete;

import com.joseph.validation.interfaces.CollectionList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author Bradley Joseph(210016299)
 */
public class CollectionListImp implements CollectionList {
    
    @Override
    public Collection myCollectionA() {

         String element;

     /*HashSet is backed by a HashMap. 
      * It makes no guarantees about the sequence 
      * of the elements when you iterate them.
      */

     Collection collectionA = new HashSet();
     String anElement  = "an element";
     collectionA.add(anElement);

     Set setA = new HashSet();
     setA.add("A");
     setA.add("B");
     setA.add("C");

     collectionA.addAll(setA);
     /*Collection target = new HashSet();
     target.addAll(setB);     //target now contains [A,B,C,1,2,3]
     //target.retainAll(setA);  //target now contains [1,2,3]

     //target.removeAll(setA);  //nothing happens - already removed
     //target.removeAll(setA);  //target is now empty.
     */
     //Iterator iterator2 =target.iterator();
     
     //access via Iterator
     Iterator iterator = collectionA.iterator();
     while(iterator.hasNext())
     {
         element = (String)iterator.next();
         System.out.println("Word: " + element);
     }

     /*while(iterator2.hasNext())
     {
         element = (String)iterator2.next();
         System.out.println("Word: " + element);
     }*/
     
     return collectionA;
 }
    
    @Override
    public Collection myCollectionB() {

     /*HashSet is backed by a HashMap. 
      * It makes no guarantees about the sequence 
      * of the elements when you iterate them.
      */

     Collection collectionB = new HashSet();
     String anElement  = "an element";
     collectionB.add(anElement);
   
     Set setB = new HashSet();
     setB.add("A");
     setB.add("B");
     setB.add("C");
     
     collectionB.addAll(setB);
     
     return collectionB;
    }

}
